<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\model\ding;

use app\common\model\ding\FriendCategory as FriendCategoryModel;
use app\api\model\ding\Friend as FriendModel;
use think\facade\Db;
/**
 * 商品评价模型
 * Class Article
 * @package app\api\model
 */
class FriendCategory extends FriendCategoryModel {
	/**
	 * 隐藏字段
	 * @var array
	 */
	protected $hidden = [
		'is_delete',
		'store_id',
		'create_time',
		'update_time',
	];

	public function add(int $shopId, array $contentList) {

		$this->deleteAll(['shop_id' => $shopId]);

		return $this->transaction(function () use ($shopId, $contentList) {
			foreach ($contentList as $content) {
				$data['name'] = $content['name'];
				$data['shop_id'] = $shopId;
				$data['create_time'] = time();
				$data['store_id'] = self::$storeId;
				$id = Db::name('ding_Friend_category')->insertGetId($data);
				// 内容
				FriendModel::increased($shopId,(int)$id, $content['Friend']);

			}
			return true;
		});
	}
	/**
	 * 获取文章列表
	 * @param int $categoryId
	 * @param int $limit
	 * @return \think\Paginator
	 * @throws \think\db\exception\DbException
	 */
	public function getListShop(int $shopId = 0) {
		// 检索查询条件
		$filter = [];

		// 获取列表数据
		return $this->with(['Friend'])
			->where($filter)

			->where('shop_id', '=', $shopId)
			->where('is_delete', '=', 0)
			->order(['create_time' => 'desc'])
			->select()->toArray();
	}

}